package org.web.datajpa.util;


import org.web.datajpa.constant.ResultEnum;
import org.web.datajpa.vo.Result;

public class ResultUtil {

    // 成功
    public static Result success(Object data) {
        Result result = new Result();
        result.setCode(200);
        result.setData(data);
        result.setMsg("成功");
        return result;
    }
    // 成功，无数据返回
    public static Result success() {
        return success(null);
    }
    // 错误时返回
    public static Result error(Integer code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
    // 错误
    public static Result error( String msg) {
        Result result = new Result();
        result.setMsg(msg);
        return result;
    }
    // 错误
    public static Result error(ResultEnum resultEnum) {
        Result result = new Result();
        result.setCode(resultEnum.getCode());
        result.setMsg(resultEnum.getMsg());
        return result;
    }
}
